<template>
<div>
 
<!-- 父评论 -->
<div class="parent">
  <!-- 递归然后判断如果有父组件传过来的参数，那么就使用 -->
  <comment v-if="parent.parent" :parent='parent.parent' @parentReply="reply" ></comment>
<div class="parent-header">
  <span>{{parent.user.nickname}}</span>
  <span>{{parent.create_date}}</span>
  <span class="reply" @click="reply(parent)">回复</span>
</div>
<div class="parent-body">
  {{parent.content}}
  </div>
</div>
</div>
</template>

<script>
export default {
  //递归组件自己调用自己，起到嵌套组件的作用
  name:'comment',
 props:{
   parent:Object
 },
   methods: {
    reply(parent) {
      // console.log(parent);
      this.$emit("parentReply", parent);
    },
  },
};
</script>

<style lang="less" scoped>
.parent {
  border: 1px solid #f00;
  padding: 5px;
  .parent-header {
    font-size: 12px;
    color: #999;
    display: flex;
    .date {
      margin-left: 10px;
      flex: 1;
    }
    .reply{
      position: relative;
      z-index: 11;
      color:#f00;
    }
  }
  .parent-body {
    font-size: 14px;
    margin: 5px 0;
  }
}
</style>